package cn.pfz.Utils;

import lombok.Data;

/**
 * @Author: 普发忠
 * @Date: 2021/09/28/15:53
 * 返回类型的集合类
 */
@Data
public class JsonResult<T> {
    public static final int CODE_SUCCESS=200;
    public static final String MSG_SUCCESS ="成功";
    
    public static final int CODE_NOLOGGING =401;
    public static final String MSG_NOLOGGING ="请先登录";
    
    public static final int CODE_ERROR=500;
    public static final String MSG_ERROR ="系统异常，请联系管理员";
    
    public static final int CODE_ERROR_PARMA=501;
    public static final String MSG_ERROR_PARMA ="参数异常";
    
    private int code;//区分不同结果
    private String msg; //返回提示信息
    private T data;       //返回携带数据的
    
    public JsonResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    
    public static <T> JsonResult  success(T data){
        return  new JsonResult(CODE_SUCCESS,MSG_SUCCESS,data);
    }
    public static <T> JsonResult  success(){
        return  new JsonResult(CODE_SUCCESS,MSG_SUCCESS,null);
    }
    
    public static <T> JsonResult  error(int code,String msg,T data){
        return  new JsonResult(code,msg,data);
    }
    public static  JsonResult  defaultError(){
        return  new JsonResult(CODE_ERROR,MSG_ERROR,null);
    }
    //登录使用
    public static JsonResult noLogin(){
        return  new JsonResult(CODE_NOLOGGING,MSG_NOLOGGING,null);
    }
}
